- search_parameter_id = discerner_nested_record_id(f, :search_parameter)

- if f.object.disabled? && f.object.warnings.any?
  %tr.error
    %td
    %td.warnings{colspan: "3"}
      %span
        = f.object.warnings.full_messages.join(', ')

%tr{ id: "#{search_parameter_id}", class: "search_parameter fields #{'error' if f.object.warnings.any?}" }
  %td.parameter_boolean_operator
    %span
      where
  %td.parameter
    %div{class: 'ui-widget categorized_autocompleter'}
      = f.hidden_field :display_order
      = f.select(:parameter_id, parameter_options(@searchable_parameters, search_parameter_id), { include_blank: true },{ class: 'parameters_combobox_autocompleter' })
      %a{ href: 'javascript:void(0);', class: 'categorized_autocompleter_link collapsed_categorized_autocompleter_link' }
        Select
      .div-category-popup{ style: "display: none;"}
        .div-category-list
          - @searchable_parameter_categories.each do |parameter_category|
            = div_for parameter_category, class: "#{parameter_category.dictionary.css_class_name}" do
              %p{ class: 'parameter_category_name' }
                = parameter_category.name
              - items = @searchable_parameters.select{|sp| sp.parameter_category_id == parameter_category.id}.sort{|a,b| a.name <=> b.name}.map{ |p| {name: p.name, rel: searchable_object_index(p, search_parameter_id)}}
              - unless items.empty?
                = render partial: 'discerner/shared/categorized_autocompleter_items', locals: { columns_count: 4, items: items }

        .div-instruction-bar
  %td.remove
    = discerner_link_to_remove_fields 'Remove', f, :search_parameters
  %td.parameter_values
    .search_parameter_values
      %table{ class: 'records' }
        %tbody.nested_records_search_parameter_values
          = f.fields_for :search_parameter_values, f.object.search_parameter_values.ordered_by_display_order do |search_parameter_value_form|
            = render partial: 'search_parameter_value_fields', locals: { f: search_parameter_value_form }
      %span{ class: 'add_header'}
        = discerner_link_to_add_fields "Add selection", :search_parameter_values, {style: "display:none;"}

:javascript
  $(function () {
    var searchParameterValuesTemplate = '#{discerner_generate_nested_attributes_template(f, :search_parameter_values, "search_parameter_value")}',
      container = $('##{search_parameter_id}'),
      parametersUrl = decodeURIComponent('#{values_parameters_url(parameter_id: ':question_id', search_parameter_value_id: ':search_parameter_value_id')}'), // used to generate parameter values for combobox parameters
      searchParameterUI = new Discerner.SearchParameterValue.UI({ container: container, searchParameterValuesTemplate: searchParameterValuesTemplate, parametersUrl: parametersUrl });
  });